<template>
  <router-view />
</template>
<script setup>
import { useConfigStore } from '@/store/modules/config'
const configStore = useConfigStore()
let reloadIndex = null


onMounted(async () => {
  try {
    
    const response = await fetch('/config.json')
    if (!response.ok) {
      throw new Error('配置文件加载失败')
    }
    const data = await response.json()
    console.log('配置文件', data)
    configStore.setConfig({ standbyTime: data.standbyTime, backHomeTime: data.backHomeTime, reloadTime: data.reloadTime })
    if (reloadIndex) clearInterval(reloadIndex)
    reloadIndex = setInterval(() => {
      console.log('启动定时刷新基础数据')
      configStore.init()
    }, data.reloadTime)
  } catch (err) {
    console.error('加载配置文件出错:', err)
  }

  document.addEventListener(
    'dblclick',
    (e) => {
      e.preventDefault()
    },
    { passive: false }
  )
  document.addEventListener(
    'touchstart',
    (e) => {
      if (e.touches.length > 1) {
        e.preventDefault()
      }
    },
    { passive: false }
  )
  // 添加长按事件阻止
  document.addEventListener(
    'contextmenu',
    (e) => {
      e.preventDefault()
    },
    { passive: false }
  )

  // 添加触摸长按事件阻止
  document.addEventListener(
    'longpress',
    (e) => {
      e.preventDefault()
    },
    { passive: false }
  )
})
</script>
<style scoped></style>
